defmodule ProgContest.Contests.Contest do
  use Ecto.Schema
  import Ecto.Changeset

  alias ProgContest.Quizzes.Quiz

  schema "contests" do
    field :end_at, :utc_datetime
    field :name, :string
    field :start_at, :utc_datetime

    has_many :quizzes, Quiz

    timestamps(type: :utc_datetime)
  end

  @doc false
  def changeset(contest, attrs) do
    contest
    |> cast(attrs, [:name, :start_at, :end_at])
    |> validate_required([:name, :start_at, :end_at])
  end
end
